package com.Extends.Abstract;

public class AnimalDemo {
    public static void main(String[] args) {
        Cat c = new Cat();
        c.setName("小花");
        c.setAge(4);
        System.out.println(c.getName()+","+c.getAge());
        c.eat();

        Cat c1 = new Cat("小红",3);
        System.out.println(c1.getName()+","+c1.getAge());
        c1.eat();

        Dog d = new Dog();
        d.setName("老花");
        d.setAge(2);
        System.out.println(d.getName()+","+d.getAge());
        d.eat();

        Dog d1 = new Dog("老红",5);
        System.out.println(d1.getName()+","+d1.getAge());
        d1.eat();

        System.out.println("--------------------");
        //按照多态的形式创建对象
        //Animal a1 = new Animal();
        // 抽象类无法实例化，可以采用多态的方法来间接实现实例化
        Animal a = new Cat("加菲猫",5);
        Animal b = new Dog("加肥狗",7);
        System.out.println(a.getName()+","+a.getAge());
        a.eat();
        System.out.println(b.getName()+","+b.getAge());
        b.eat();

    }
}
